using Client.Base;
using UnityEngine;
namespace Client.Hotfix
{
    [UGFM(UGFMWeight.DeviceService)]
    public class DeviceService : IAwake
    {
        public string AbsoluteURL { get; private set; } = null;
        public void Awake()
        {
            AbsoluteURL = Application.absoluteURL;
            Application.deepLinkActivated += OnDeepLinkActivated;
            UniApp.Instance.onApplicationFocus = OnApplicationFocus;
            UniApp.Instance.onApplicationPause = OnApplicationPause;
            this.Log("DeviceComponent is Running");
        }

        public void Destroy()
        {
            Application.deepLinkActivated -= OnDeepLinkActivated;
        }
        /// <summary>
        /// 当前运行设备的唯一标识符
        /// </summary>
        /// <returns></returns>
        public string GetDeviceID()
        {
            return SystemInfo.deviceUniqueIdentifier;
        }
        /// <summary>
        /// 设备型号
        /// </summary>
        /// <returns></returns>
        public string GetDeviceModel()
        {
            return SystemInfo.deviceModel;
        }
        /// <summary>
        /// 设备类型
        /// </summary>
        /// <returns></returns>
        public string GetDeviceType()
        {
            return SystemInfo.deviceType.ToString();
        }

        /// <summary>
        /// 操作系统名称
        /// </summary>
        /// <returns></returns>
        public string GetOperatingSystem()
        {
            return SystemInfo.operatingSystem;
        }
        /// <summary>
        /// 设备名称
        /// </summary>
        /// <returns></returns>
        public string GetDeviceName()
        {
            return SystemInfo.deviceName;
        }
        /// <summary>
        /// 操作系统版本
        /// </summary>
        /// <returns></returns>
        public string GetOperatingSystemFamily()
        {
            return SystemInfo.operatingSystemFamily.ToString();
        }
        /// <summary>
        /// 电池电量(0.0-1.0)
        /// </summary>
        /// <returns></returns>
        public float GetBatteryLevel()
        {
            return SystemInfo.batteryLevel;
        }

        private void OnApplicationFocus(bool focus)
        {

        }

        private void OnApplicationPause(bool pause)
        {

        }

        private void OnDeepLinkActivated(string link)
        {
            AbsoluteURL = link;

        }

    }

}
